import userDao,{ Userinfo } from '../dao/UserDao'
import jwt from 'jsonwebtoken'
class UserService{
  static userService: UserService = new UserService()
  async login(username: string, psw: string){
    const userinfo:any = await userDao.findOneUser(username,psw);
    this.createJWTToken(userinfo);
    return userinfo;
  }
  createJWTToken(userinfo: Userinfo) {
   let af =  {expiresln: '30h', header: { alg: 'HS256', type: 'JwT' } };
    const token:string= jwt.sign({ data: userinfo },'9abd3cd33dff', af);
    userinfo.token = token;
  }
}
export default UserService.userService
